# -*- coding: UTF-8 -*-
__author__ = 'BK'
import mailText
import jiebaUtility
import bayesUtility
import numpy
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()

mails=mailText.mails()
words=[]

for i in mails:
    words.append(jiebaUtility.cut(i))

dictn=bayesUtility.createVocabList(words)

trainM=[]

for i in words:
    trainM.append(bayesUtility.setOfWords2Vec(dictn,i))

print len(trainM)
classes = [1]*40
classes.extend([0]*25)

from sklearn.externals import joblib

gnb.fit(numpy.array(trainM), numpy.array(classes))
import os,sys
path = os.getcwd()
parent_path = os.path.dirname(path)

# joblib.dump(gnb,'model.pkl')

#y_pred = gnb.fit(numpy.array(trainM), numpy.array(classes)).predict(trainM)
# sys.path.index(parent_path+'\model')

y_pred = joblib.load(parent_path+'\\model\\model.pkl').predict(trainM)
print y_pred

#test='尊敬的bk您好：感谢您在京东( JD.COM ) 购物! 我们已经收到了您的订单10337405705，会尽快为您安排发货。您选择的是在线支付的支付配送方式，我们已收到款项'
# 订单信息以“我的订单”页面显示为准，您也可以随时进入页面对订单进行修改等操作'
#test='我叫李涛，从农村来的，这个东西改变了我的命运，比上班舒服多了 www.abnecc.com现在介绍给大家一起，复制去浏览器就可以了'
#test='一个月的准备公考时间够吗'
#test='豪哥说：说什么都行么?'
test='编程指导，机器学习算法'


a=gnb.fit(numpy.array(trainM), numpy.array(classes)).predict(bayesUtility.setOfWords2Vec(dictn,jiebaUtility.cut(test)))

print a
#print("Number of mislabeled points out of a total %d points : %d"
#     % (numpy.array(trainM).shape[0],(classes != y_pred).sum()))